home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / filesyst / ncpfs / mars_dos.000 / mars_dos / netpc / demoprn.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-05  |  1.2 KB  |  50 lines

  1. /*
  2.  * very simple demo for a printerclient running with mars_nwe
  3.  * a real printerclient should be made in assembler
  4.  * as a resident program.
  5.  * the simple idea is to open a named pipe at the mars_nwe server
  6.  * and spool all data to the printer.
  7.  */
  8.  
  9. #include <stdio.h>
  10.  
  11. static int usage(char *progname)
  12. {
  13.   fprintf(stderr, "Usage:\t%s attachfile printer\n", progname);
  14.   return(1);
  15. }
  16.  
  17. static FILE *fopen_err(char *fn, char *openmode)
  18. {
  19.   FILE *f=fopen(fn, openmode);
  20.   if (NULL == f) {
  21.     fprintf(stderr, "Open error '%s' with mode='%s'\n", fn, openmode);
  22.   }
  23.   return(f);
  24. }
  25.  
  26. int main(int argc, char *argv[])
  27. {
  28.   if (argc > 2) {
  29.     FILE *fa=fopen_err(argv[1], "rb");
  30.     if (NULL != fa) {
  31.       FILE *fo=fopen_err(argv[2], "w+b");
  32.       if (NULL != fo) {
  33.         char buf[512];
  34.         int k;
  35.         while (1) {
  36.           if (0 != (k=fread(buf, 1, sizeof(buf), fa))) {
  37.             if (1 != fwrite(buf, k, 1, fo)) {
  38.               fprintf(stderr, "Writerror in %s\n", argv[2]);
  39.             }
  40.           } else sleep(2);
  41.         }
  42.       } else
  43.         return(usage(argv[0]));
  44.       fclose(fa);
  45.     } else
  46.       return(usage(argv[0]));
  47.   } else return(usage(argv[0]));
  48.   return(0);
  49. }
  50.